package com.yanqu.road.server.cmd.activity.zhenhuan;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanMgr;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanThirdProcessActivity;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_CROSS_ZHENHUAN_THIRD_PROCESS_GET_ALL_USER, desc = "获取参赛者信息")
public class CrossZhenHuanThirdProcessGetAllUserCmd extends CrossCommand {

    private int activityId;

    private long targetUserId;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ZhenHuanProto.CrossZhenHuanThirdProcessGetAllUserReqMsg reqMsg = ZhenHuanProto.CrossZhenHuanThirdProcessGetAllUserReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        targetUserId = reqMsg.getTargetUserId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossZhenHuanThirdProcessActivity activity = CrossZhenHuanMgr.getThirdProcessActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_ZHENHUAN_THIRD_PROCESS_ACTIVITY_NOT_FOUND;
            return;
        }

        // 拉参赛成员列表
        ret = activity.getAllUserByCmd(serverId, userId, targetUserId);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            ZhenHuanProto.ZhenHuanThirdProcessGetAllUserRespMsg.Builder respMsg = ZhenHuanProto.ZhenHuanThirdProcessGetAllUserRespMsg.newBuilder();
            respMsg.setRet(0);
            MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(Protocol.U_ZHENHUAN_THIRD_PROCESS_GET_ALL_USER, respMsg));
        }
    }
}
